TryAdd Method

Task Parallel System.Threading

Attempts to add the specified key and value to the ConcurrentDictionary<(Of <(TKey, TValue>)>).

Namespace:  System.Collections.Concurrent
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Function TryAdd ( _
	key As TKey, _
	value As TValue _
) As Boolean
C#
public bool TryAdd(
	TKey key,
	TValue value
)

Parameters

key
Type: TKey
The key of the element to add.
value
Type: TValue
The value of the element to add. The value can be a null reference (Nothing in Visual Basic) for reference types.

Return Value

true if the key/value pair was added to the ConcurrentDictionary<(Of <(TKey, TValue>)>) successfully; otherwise, false.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionkey is null reference (Nothing in Visual Basic).
System..::.OverflowExceptionThe ConcurrentDictionary<(Of <(TKey, TValue>)>) contains too many elements.

See Also